package com.wltt.product.frfront.config;

import com.wltt.product.frfront.config.javafx.JavafxStarter;
import com.wltt.product.frfront.constants.JavaFxEnableConstant;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.ResourceLoader;

import java.io.IOException;

@Configuration
@ConditionalOnProperty(
        prefix = "javafx",
        name = "enable",
        havingValue = JavaFxEnableConstant.ENABLE,
        matchIfMissing = true
)
public class JavaFxConfig {

    @Resource
    private ResourceLoader resourceLoader;

    @Bean
    public JavafxStarter javafxStarter() throws IOException {
//        ClassPathResource classpathResource = new ClassPathResource("javafx/main-windows.fxml");
        ClassPathResource classpathResource = new ClassPathResource("javafx/login.fxml");
        JavafxStarter javafxStarter = new JavafxStarter(classpathResource.getURL());
        javafxStarter.startJavafx();
        return javafxStarter;
    }
}
